//
//  QuickEditAmountViewModel.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 09.05.25.
//

import Foundation
class QuickEditAmountViewModel : KoiAccountingBaseViewModel {
    
    @Published var detail: AccountingDetailCombine = AccountingDetailCombine.previewData()
    @Published var amount = ""
    @Published var reset = false
    
    @Published var updateState = ""
    
    private let detailDao = KoiAccountingDB.standard.getDetailDao()
    
    func updateAmount() {
        let amount = Double(amount)
        if amount == 0.0 {
            updateState = "请输入金额"
            return
        }
        var detail = detail.detail
        asyncBackground {
            detail.amount = amount
            self.detailDao.updateRecord(detail: detail)
            self.asyncMain {
                self.updateState = "success"
            }
        }
    }
}
